<?php
class tree{
	private $rows=array();
	public function init($params){
		foreach($params as $key=>$var){
			$this->$key=$var;
		}
	}
	public function set(&$rows){
		$this->rows=$rows;
	}
	public function child($id){
	    $childs=array();
	     foreach($this->rows as $k => $v){
	         if($v['parent']== $id){
	              $childs[]=$v;
	         }
	    }
	    return $childs;
	}
	public function build($id){
	    $childs=$this->child($id);
	    if(empty($childs)){
	        return null;
	    }
	   foreach($childs as $k => $v){
	       $rescurTree=$this->build($v['id']);
	       if(null!=$rescurTree){
	       	 $childs[$k]['child']=$rescurTree;
	       }
	   }
	    return $childs;
	}
}
?>